# -*- encoding=utf8 -*-
__author__ = "yangxianming"

from airtest.core.api import *
# ST.PROJECT_ROOT = "E:\AirtestWorkSpace\fuyuanwaiUItest"
# using(r"E:\AirtestWorkSpace\fuyuanwaiUItest\common.air")
# from common import *

auto_setup(__file__)

#拿到设备编号
import sys
args = sys.argv
devicePid = args[4].split("/")[3]
print("--------" + devicePid)
rootArr = args[2].split("\\")
scriptRoot = ""
for i in range(len(rootArr) - 1):
    scriptRoot = scriptRoot + rootArr[i] + "\\"
print("--------" + scriptRoot)

#对更目录下设变编号文件做注册登记操作 1代表在使用  0代表停止使用
with open(scriptRoot + devicePid, 'w') as f:
    f.write('1')
    
using(scriptRoot + "common.air")

from common import *
stop_app("com.alibaba.android.rimet")
start_app("com.alibaba.android.rimet")

try:
    sleep(1.0)
    openKoufu()
    sleep(3.0)
    #划上来
    swipe((500, 1200), (500, 300), duration=2)
    sleep(1.0)
    #点美团
    touch(Template(r"tpl1683708727558.png", resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683709040927.png", record_pos=(-0.335, -0.298), resolution=(1080, 1920)))
    sleep(1.0)
    text("13555555555")
    sleep(1.0)
    touch(Template(r"tpl1684425877196.png", record_pos=(0.243, 0.755), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1683709188783.png", record_pos=(0.224, 0.252), resolution=(1080, 1920)))
    sleep(1.0)
    
    #验证是否有充值产品
    assert_exists(Template(r"tpl1683709213685.png", record_pos=(-0.274, 0.735), resolution=(1080, 1920)), "验证是否有充值产品")


    
except Exception as e:
    print(e)
finally:
    sleep(1.0)
    stop_app("com.alibaba.android.rimet")
    #完成测试等级设备为0以便被其他脚本使用
    with open(scriptRoot + devicePid, 'w') as f:
        f.write('0')
